$KCODE = 'U'

require 'gtk2'
require 'libglade2'
require 'note'
include Gtk

module Verynotes
  class MainWindow
    def initialize
      @xml = GladeXML.new('ui/main.glade'){|handler|
        method(handler)
      }
      @win = @xml['window']
      @win.show_all
    end

    def method_missing(method, *args)
      puts "#{method}: #{args}"
    end
    
    def on_window_destroy(widget)
      main_quit()
    end

    def on_new(widget)
      nwin = NoteWindow.new()
    end

    def on_delete(widget)
    
    end

  end

  class NoteWindow
    def initialize()
      @xml = GladeXML.new('ui/note.glade'){|handler|
        method(handler)
      }
      @win = @xml['window']
      @textview = @xml['textview']
      @win.show_all
      @cursor = Gdk::Cursor.new(Gdk::Cursor::RIGHT_PTR)
    end
    
    def method_missing(method, *args)
      puts "#{method}: #{args}"
    end

    def on_window_button_press(widget, event)

    end
    
    def on_textview_button_press(widget, event)
      pos = @win.position
      size = @win.size
      p event.class
      if event.class == Gdk::Event::BUTTON2_PRESS
        p 1
      else
        unless @textview.editable?
          @win.begin_move_drag(event.button, event.x_root, event.y_root, event.time)
        end
      end
    end

    def on_textview_motion(widget, event)
      widget.window.set_cursor(@cursor)
    end

  end
end
Verynotes::MainWindow.new
#Verynotes::NoteWindow.new

main